/**
 * 项目管理的复制modal
 * @author: zxy
 * @update: 2017-03-20
 */

import React, {PropTypes} from 'react';
import {Modal, Form, InputNumber} from 'antd';
const FormItem = Form.Item;
import styles from './ProjectManageCopy.less';

const ProjectManageCopy = ({
  visible,
  copyNum,
  copyId,
  onOk,
  onCancel,
  form: {
    validateFields,
    getFieldsValue,
    resetFields,
    getFieldDecorator,
  },
}) => {


  function handleOk() {
    validateFields((errors) => {
      if (errors) {
        return;
      }

      const formData = getFieldsValue();
      formData.copyId = copyId;

      console.log(formData)

      // onOk(data, () => {
      //   resetFields();
      // });

    });
  };

  function handleCancle() {
    resetFields();
    onCancel();
  }

  const modalOpts = {
    title: '请输入复制个数',
    visible: visible,
    width: 300,
    maskClosable: false,
  }

  return (
    <Modal {...modalOpts} onOk={handleOk} onCancel={handleCancle}>
      <div className={styles.wrap}>
        <Form>
          <FormItem>
            {getFieldDecorator('copyNum', {
              initialValue: 1,
              rules: [
                {type: 'number', message:'请输入个数'},
              ],
            })(
              <InputNumber min={1} max={20} />
            )}
            <span className={styles.money}>个</span>
          </FormItem>
        </Form>
      </div>
      <div>复制功能，用于快速生成产品，复制后系统将会生成{`${copyNum ? copyNum : 1}`}个产品</div>
    </Modal>
  );
};

ProjectManageCopy.propTypes = {
  visible: PropTypes.any,
  item: PropTypes.object,
};

export default Form.create({
  onFieldsChange(props, changedFields) {
    props.onChange(changedFields);
  },
})(ProjectManageCopy);